#include "_mysql.h"
_mysql::_mysql(string bdd,string user,string pass)
{
    static int cCount = 0;
    QSqlError err;
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", QString("Browser%1").arg(++cCount));
    db.setDatabaseName(bdd.data());
    db.setHostName("localhost");
    db.setPort(3360);
    if (!db.open(user.data(), pass.data())) {
    err = db.lastError();
    db = QSqlDatabase();
    QSqlDatabase::removeDatabase(QString("Browser%1").arg(cCount));
    }
    this->db=db;
}
_mysql::~_mysql()
{
    this->db.close();
}
QSqlQueryModel* _mysql::exec(const QString & query)
{
    QSqlQueryModel *model = new QSqlQueryModel();
    model->setQuery(QSqlQuery(query, this->db));
    return model;
}
